<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');

$time = date('h:i:s A');

$data[ 'html' ] = "Server time is: {$time}";
echo 'data: ' . json_encode( $data ) . "\n\n";

flush();

?>

<!DOCTYPE html>
<html>
	<head>
		<title>SSE</title>
	</head>
	<body>
		<h1>Getting server updates</h1>
		<div id="eventResult"></div>
		<script>
		 	if( typeof( EventSource ) !== "undefined" ) {
			    var source = new EventSource( "/ajax/event/" );
			    source.onmessage = function( result ) {
				var data = JSON.parse( result.data );
			    	//document.getElementById( "eventResult" ).innerHTML += data.html + "<br>";
			    	document.getElementById( "eventResult" ).innerHTML = data.html;
			    };
			} else {
			    document.getElementById( "eventResult" ).innerHTML = "Sorry, your browser does not support server-sent events...";
			}
		</script>
	</body>
</html>



